2 using System.Collections.Generic;
5 using Microsoft.Xna.Framework;
6 using Microsoft.Xna.Framework.Graphics;
8 namespace SuperPolarity
12 public enum Polarity : byte { Negative, Positive, Neutral };
14 public Polarity CurrentPolarity;
15 public uint MagneticRadius;
17 public float FleeVelocity;
18 public float ActVelocity;
19 public float ChargeVelocity;
20 protected int RepelRadius;
22 protected bool Magnetizing;
24 public Ship(SuperPolarity newGame) : base(newGame) {
32 ChargeVelocity = 2.5f;
33 CurrentPolarity = Polarity.Neutral;
37 public virtual void SwitchPolarity()
39 if (CurrentPolarity == Polarity.Positive)
41 CurrentPolarity = Polarity.Negative;
45 CurrentPolarity = Polarity.Positive;
49 public virtual void SetPolarity(Polarity newPolarity)
51 CurrentPolarity = newPolarity;
54 public virtual void Shoot()
58 public override void Update(GameTime gameTime)
60 base.Update(gameTime);
64 public virtual void Magnetize(Ship ship, float distance, float angle)
67 Polarity polarity = ship.CurrentPolarity;
69 if (polarity != CurrentPolarity)
75 Repel(distance, angle);
79 protected void Attract(float angle)
81 Velocity.X = (float) (ChargeVelocity * Math.Cos(angle));
82 Velocity.Y = (float) (ChargeVelocity * Math.Sin(angle));
85 protected void Repel(float distance, float angle)
87 if (distance > RepelRadius) { Magnetizing = false; return; }
88 Velocity.X = -(float)(FleeVelocity * Math.Cos(angle));
89 Velocity.Y = -(float)(FleeVelocity * Math.Sin(angle));